package com.talkyun.openx.ocean;

import com.talkyun.ocean.RegistryClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RegistryManager {
    private final static Logger logger = LoggerFactory.getLogger(RegistryManager.class);
    private final static RegistryManager instance = new RegistryManager();
    private RegistryClient client;
    private String registryUrl;

    private RegistryManager() {
    }

    public static RegistryManager get() {
        return instance;
    }

    public RegistryClient getRegistryClient() {
        if (client != null) {
            return client;
        }
        if (registryUrl == null || registryUrl.trim().length() == 0) {
            client = new RegistryClient();
        } else {
            client = new RegistryClient(registryUrl);
        }
        return client;
    }

    public void updateUrl(String url) {
        this.registryUrl = url;
        logger.info("Using registry url {}", url);
    }
}